package com.prototipo_picshare;

import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Configuracion extends Activity implements OnClickListener {
	BluetoothAdapter btAdapter;
	EditText mail;
	EditText Pass;
	EditText Pass2;
	EditText NomGrupo;
	Button guardar;
	Button regresar;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_configuracion);
		btAdapter = BluetoothAdapter.getDefaultAdapter();
		btAdapter.enable();
		//guardar conf
  		guardar=(Button) findViewById(R.id.BTGuardar_config);
  		guardar.setOnClickListener(this);
  		
  		//regresar conf
  		regresar=(Button) findViewById(R.id.BTRegresar_configuracion);
  		regresar.setOnClickListener(this);
  		
  	//text files
  		mail=(EditText) findViewById(R.id.ETEmail);
  		Pass=(EditText) findViewById(R.id.ETPass);
  		Pass2=(EditText) findViewById(R.id.ETPass2);
  		NomGrupo=(EditText) findViewById(R.id.ETNomGrupo);
  		
  		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.configuracion, menu);
		return true;
	}
	
	@Override
	public void onClick(View v) {
		
		switch (v.getId()) 
		{
			case R.id.BTRegresar_configuracion:
				btAdapter.enable();
				
				mail.setText("takitomaj@gmail.com");
				Pass.setText("55552735");
				Pass2.setText("55552735");
				String direccion=btAdapter.getAddress();
				String nombre=btAdapter.getName();
				
				if(direccion==null||nombre==null){
					NomGrupo.setText("");
				}else{
					NomGrupo.setText(direccion+"/"+nombre);
				}
				btAdapter.disable();
			break;
			case R.id.BTGuardar_config:
				
				Toast.makeText(getBaseContext(), "guardando configuracion", Toast.LENGTH_LONG).show();
				int error=0;
				if(mail.getText().equals("")||mail.getText()==null){
					error++;
					Toast.makeText(getBaseContext(), "Mail sin valor", Toast.LENGTH_LONG).show();
				}
				if(Pass.getText().equals("")||Pass.getText()==null){
					error++;
					Toast.makeText(getBaseContext(), "contrasena sin valor ", Toast.LENGTH_LONG).show();
				}
				if(Pass2.getText().equals("")||Pass2.getText()==null){
					error++;
					Toast.makeText(getBaseContext(), "debe repetir contrasena", Toast.LENGTH_LONG).show();
				}
				if(error>0){
					Toast.makeText(getBaseContext(), "alguno de los campor obligatorios son nulos", Toast.LENGTH_LONG).show();
				}
				
			break;
			

			default:
		break;
		
		}
		

		
	}

}
